import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/me/data/api/service_post_order_api.dart';
import 'package:casdon/modules/me/data/repository/me_repository.dart';
import 'package:casdon/modules/me/data/repository/me_repository_impl.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class ServiceSaveOrderidUsecase {
  final MeRepository _repository;

  const ServiceSaveOrderidUsecase(this._repository);

  Future<bool> execute(String reqId) async {
    try {
      await _repository.postServiceOrderReqId(orderReqId: reqId);
      return true;
    } on BusinessException catch (e) {
      rethrow;
    } catch (e) {
      Log.e("ServiceSaveOrderidUsecase 失败", e.toString(), StackTrace.current);
      throw Exception("ServiceSaveOrderidUsecase 失败");
    }
  }
}

final serviceSaveOrderidUsecaseProvider = Provider(
  (ref) => ServiceSaveOrderidUsecase(ref.read(meRepositoryProvider)),
);
